package com.zzjson.producer;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zzjson.domain.Merchant;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.producer</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月28日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
@Component
public class RabbitSender {
	@Autowired
	private AmqpTemplate amqpTemplate;

	public void send() throws JsonProcessingException {
		Merchant merchan = new Merchant();
		merchan.setName("name");
		// amqpTemplate.convertAndSend("boot-topic-exchange", "test.zzy.test", "---------topic-------" + merchan);
		// amqpTemplate.convertAndSend("boot-fanout-exchange", "", merchan);
		// 发送json数据到广播
		merchan.setId(22);
		merchan.setName("fanout-exchange");
		merchan.setAddress("测试地址");
		ObjectMapper objectMapper = new ObjectMapper();
		String json = objectMapper.writeValueAsString(merchan);
		System.out.println(json);
		amqpTemplate.convertAndSend("boot-direct-exchange", "test", merchan);
		amqpTemplate.convertAndSend("boot-direct-exchange", "test", json);
		// HashMap hashMap = new HashMap();
		// hashMap.put("id", 123);
		// amqpTemplate.convertAndSend("boot-direct-exchange", "test", json);
	}
}